package com.neishenmo.sochatapp.network;

import android.content.Intent;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;


import java.util.Map;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import rx.Subscriber;

/**
 * 创建人： wushixin
 * 创建日期：2017/10/26
 * 内容：
 */

public class ApiPresenter implements ApiConstract.presenter {

    ApiTask mTask;
    ApiConstract.view mView;

    public ApiPresenter(ApiConstract.view view) {
        mView = view;
        mTask = new ApiTask();
    }

    /**
     * 注册
     */
    @Override
    public void loadRegistUser(RequestBody string) {
        Log.e("body",string.toString());
        mTask.getRegistUser(new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mView.showErrMsg("--------------->" + e.getMessage());
                Log.e("错误", e.getMessage());
            }

            @Override
            public void onNext(String news) {
                mView.showInfo(news);

            }
        }, string);
    }
    /**
     * 发送外部验证码（登陆、注册）
     */
    @Override
    public void loadSendExternalCode(RequestBody string) {
        Log.e("body",string.toString());
        mTask.getSendExternalCode(new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mView.showErrMsg("--------------->" + e.getMessage());
                Log.e("错误", e.getMessage());
            }

            @Override
            public void onNext(String news) {
                mView.showInfo(news);

            }
        }, string);
    }
    /**
     * 用户登录
     */
    @Override
    public void loadUserLogin(RequestBody string) {
        Log.e("body",string.toString());
        mTask.getSendExternalCode(new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                mView.showErrMsg("--------------->" + e.getMessage());
                Log.e("错误", e.getMessage());
            }

            @Override
            public void onNext(String news) {
                mView.showInfo(news);

            }
        }, string);
    }

}
